function getUrlParams(url) {
	if (url) {
		// 通过 ? 分割获取后面的参数字符串
		let urlStr = url.split('?')[1]
		// 创建空对象存储参数
		let obj = {};
		if (urlStr) {
			// 再通过 & 将每一个参数单独分割出来
			let paramsArr = urlStr.split('&')
			for (let i = 0, len = paramsArr.length; i < len; i++) {
				// 再通过 = 将每一个参数分割为 key:value 的形式
				let arr = paramsArr[i].split('=')
				obj[arr[0]] = arr[1];
			}
			return obj
		}
	}
}
var watchUnit = new Vue({
	el: '#watchUnit',
	data: {
		popupVisible: false,
		pickerValue: '',
		info: {
			lable: '',
			unit: '',
			type: 1
		},
		list: [],
		slots: [],
		params: getUrlParams(window.location.href)
	},
	created(){
		if(this.params.type == 2){
			this.list = [
				{
					lable: '时间格式',
					value: '24',
					unit: true,
					type: 1
				}]
		}else{
			this.list = [
				{
					lable: '单位设置',
					value: '英制',
					unit: true,
					type: 1
				}, {
					lable: '重量',
					value: '镑',
					unit: false,
					type: 2
				}, {
					lable: '长度',
					value: '英里',
					unit: false,
					type: 3
				}, {
					lable: '温度设置',
					value: '℉',
					unit: true,
					type: 4
				}
			]
		}
	},
	mounted() {
	},
	methods: {
		confirm() {
			this.popupVisible = false;
			if (this.pickerValue) {
				this.list[this.info.type - 1].value = this.pickerValue
			}
		},
		onValuesChange(_, values) {
			this.pickerValue = values[0]
		},
		showPicker(info) {
			this.info = info
			this.popupVisible = true;
			switch (info.type) {
				case 1:
					if(this.params.type == 2){
						this.slots = [{
							flex: 1,
							values: ['24','12'],
							defaultIndex: ['24','12'].map(v => v).indexOf(info.value)
						}]
					}else{
						this.slots = [{
							flex: 1,
							values: ['公制','英制'],
							defaultIndex: ['公制','英制'].map(v => v).indexOf(info.value)
						}]
					}
					break;
				case 2:
					this.slots = [{
						flex: 1,
						values: ['千克','镑'],
						defaultIndex: ['千克','镑'].map(v => v).indexOf(info.value)
					}]
					break;
				case 3:
					this.slots = [{
						flex: 1,
						values: ['公里','英里'],
						defaultIndex: ['公里','英里'].map(v => v).indexOf(info.value)
					}]
					break;
				case 4:
					this.slots = [{
						flex: 1,
						values: ['℃','℉'],
						defaultIndex: ['℃','℉'].map(v => v).indexOf(info.value)
					}]
					break;
			}
		}
	},
})